﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data;

namespace BanHangCshap.DanhMuc.gkhtdl63
{
    public partial class frmDieukienBaohanh : Form
    {
        public frmDieukienBaohanh()
        {
            InitializeComponent();
        }

        BanHangCshap.Class.gkhtdl63.BLL.DieukienBaohanhBLL xgDieukienBaohanhBLL = new BanHangCshap.Class.gkhtdl63.BLL.DieukienBaohanhBLL();

        private void TaiDanhsachDKBH()
        {
            gcMain.DataSource = xgDieukienBaohanhBLL.DieukienBaohanh_LayDanhsach();
        }

        private void frmDieukienBaohanh_Load(object sender, EventArgs e)
        {
            TaiDanhsachDKBH();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            DanhMuc.gkhtdl63.frmDieukienBaohanhChitiet frm = new frmDieukienBaohanhChitiet(true,new BanHangCshap.Class.gkhtdl63.DAL.Entities.DieukienBaohanh());
            frm.ETailai += new MyEvent_LoadData(frm_ETailai);
            frm.ShowDialog();
        }

        void frm_ETailai(object sender, ELoadData e)
        {
            if (e.IsLoadData)
            {
                TaiDanhsachDKBH();
            }
        }

        private void gvMain_DoubleClick(object sender, EventArgs e)
        {
            BanHangCshap.Class.gkhtdl63.DAL.Entities.DieukienBaohanh xlDKBH = new BanHangCshap.Class.gkhtdl63.DAL.Entities.DieukienBaohanh();
            try
            {
                DataRow xlDataRow = gvMain.GetFocusedDataRow();
                xlDKBH.Ma = xlDataRow["Ma"].ToString();
                xlDKBH.Ten = xlDataRow["Ten"].ToString();
                xlDKBH.Mota = xlDataRow["Mota"].ToString();
                xlDKBH.Ghichu = xlDataRow["Ghichu"].ToString();
            }
            catch (Exception)
            {

            }
            DanhMuc.gkhtdl63.frmDieukienBaohanhChitiet frm = new frmDieukienBaohanhChitiet(false, xlDKBH);
            frm.ETailai += new MyEvent_LoadData(frm_ETailai);
            frm.ShowDialog();
        }

        private void gvMain_MouseWheel(object sender, MouseEventArgs e)
        {
            gvMain.GridMouseWheel(e);
        }

        private void btnXemSua_Click(object sender, EventArgs e)
        {
            gvMain_DoubleClick(null, null);
        }

        private void btnTailai_Click(object sender, EventArgs e)
        {
            TaiDanhsachDKBH();
        }
    }
}
